# @shuaige : 陈世玉
# @name :02-post请求方式.py
# @time :2024/9/19 下午10:35
import urllib.request
import urllib.parse
import json
url="https://fanyi.baidu.com/sug"
headers={"User-Agent":"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/116.0.0.0 Safari/537.36"}
data={"kw":"python"}
data=urllib.parse.urlencode(data).encode("utf-8")# 将字典转换为字符串
request=urllib.request.Request(url=url,data=data,headers=headers)
response=urllib.request.urlopen(request)
html=response.read().decode("utf-8")
html=json.loads(html) # 将字符串转换为字典  反序列化
print(html)

